//
//  VisitorCoverView.swift
//  SwiftWB
//
//  Created by luozhijun on 2016/10/1.
//  Copyright © 2016年 luozhijun. All rights reserved.
//

import UIKit

/** 访客封面视图 */
class VisitorCoverView: UIView {
    
    //MARK: - 属性
    @IBOutlet var turnplateView: UIImageView!
    @IBOutlet var backgroundView: UIImageView!
    @IBOutlet var icon: UIImageView!
    @IBOutlet var tipLabel: UILabel!
    @IBOutlet var registerBtn: UIButton!
    @IBOutlet var loginBtn: UIButton!
    
    //MARK: -
    /** 从Xib中加载view */
    class func instanceFromXib() -> VisitorCoverView {
        // 此处确定Xib存在, 并且Xib中的view也存在, 而且在xib中已把它指定为了VisitorCoverView类型, 所以可以强制解包
        return NSBundle.mainBundle().loadNibNamed("VisitorCoverView", owner: nil, options: nil)?.first as! VisitorCoverView
    }
    
    func addRotationAnimation() {
        // 绕z轴转
        let animation = CABasicAnimation(keyPath: "transform.rotation.z")
        
        animation.duration = 5.0
        animation.fromValue = 0
        animation.toValue = M_PI * 2.0
        animation.repeatCount = MAXFLOAT
        // 防止切换到其他界面再切回来 或者进入后台再回到界面 时动画停止
        animation.removedOnCompletion = false
        
        turnplateView.layer.addAnimation(animation, forKey: nil)
    }
    
    func setup(tip tip: String, iconName: String) {
        icon.image = UIImage(named: iconName)
        tipLabel.text = tip
        // homeController 中visitorView的内容即为默认内容, 所以不调用此函数
        // 故可在此处隐藏转盘
        turnplateView.hidden = true
    }
}
